import { createApp } from 'vue'
import { createPinia } from 'pinia'

import 'normalize.css'; // 清除默认演示
import 'element-plus/dist/index.css'; // element-plus 样式文件
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import App from './App.vue'
import router from './router'
import { BusinessException } from './exception/BusinessException';
import { ElMessage } from 'element-plus';
import { ParameterException } from './exception/ParameterException';

const app = createApp(App)

// 全局异常处理
app.config.errorHandler = (err, vm, info) => {
    // 处理错误
    if(err instanceof BusinessException){
        ElMessage.error(err.message);
    }else if(err instanceof ParameterException){
        ElMessage.warning(err.message);
    }else{
        ElMessage.error("页面错误");
    }
    console.error(err);
  };

app.use(createPinia())
app.use(router)

// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.mount('#app')


